Skip to content

AK: Relax ensure_capacity assertion to allow allocator-rounded capacity#8897

Open
officialasishkumar wants to merge 1 commit intoLadybirdBrowser:masterfrom
officialasishkumar:test-json-capacity-fix
Open

AK: Relax ensure_capacity assertion to allow allocator-rounded capacity#8897
officialasishkumar wants to merge 1 commit intoLadybirdBrowser:masterfrom
officialasishkumar:test-json-capacity-fix

Conversation

@officialasishkumar
Copy link
Copy Markdown

The ensure_capacity function guarantees that the resulting capacity is
at least the requested value; it does not guarantee an exact match. The
underlying try_ensure_capacity implementation asks the allocator for a
"good" size via kmalloc_good_size, which maps to mi_good_size when
mimalloc is in use. In debug builds mimalloc may return a size larger than
requested, causing the raw element count to exceed new_capacity.

The json_array_ensure_capacity test checked for exact equality (EXPECT_EQ)
which fails in debug builds with mimalloc. Switch to EXPECT_GE to test
only the weaker, actually-guaranteed postcondition.

Fixes #8876.

@ladybird-bot
Copy link
Copy Markdown
Collaborator

Hello!

One or more of the commit messages in this PR do not match the Ladybird code submission policy, please check the lint_commits CI job for more details on which commits were flagged and why.
Please do not close this PR and open another, instead modify your commit message(s) with git commit --amend and force push those changes to update this PR.

The ensure_capacity contract guarantees that the resulting capacity is
at least the requested value, not exactly equal to it. Allocators such
as mimalloc may round up the allocation to an internally efficient size
(via mi_good_size), so the actual capacity can exceed the requested
amount when building with BUILD_PRESET=Debug.

Replace EXPECT_EQ with EXPECT_GE in the json_array_ensure_capacity
test to reflect the weaker, correct postcondition.

Fixes LadybirdBrowser#8876.
@rcorsi
Copy link
Copy Markdown
Contributor

rcorsi commented Apr 14, 2026

Hi @officialasishkumar, its a good idea, but did you try the fix locally? I don't think EXPECT_GE is available, which would be available with gtest, but this is not gtest.

Have a look at: Libraries/LibTest/Macros.h

and for the BigInt some additional macros are created which could give you ideas. See Tests/LibCrypto/TestBigInteger.cpp and for example look for EXPECT_LESS

@trflynn89
Copy link
Copy Markdown
Contributor

trflynn89 commented Apr 15, 2026

@officialasishkumar Between this and other changes that were submitted and don't even build, it is quite difficult to trust any of the 10 PRs that you opened in quick succession. Do not submit PRs from AI that you have not tested and thought through yourself.

See here: https://github.com/LadybirdBrowser/ladybird/blob/master/CONTRIBUTING.md#on-usage-of-ai-and-llms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TestJSON incorrect capacity with mimalloc when BUILD_PRESET is Debug

4 participants